import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import '../FormCreator.dart';

Map<String, dynamic> filterTextFieldRules(BuildContext context, FormControlContext controlContext) {
    FormCreatorHandler formHandler = FormCreatorState.of(context);
    String errorText = formHandler.validateResult.field == controlContext.field && !formHandler.validateResult.validate ? formHandler.validateResult.msg : "";
    List<TextInputFormatter> inputFormatters = <TextInputFormatter>[];

    int maxLength = formHandler.rules?.firstWhere((item){
      return item.max != null && item.field == controlContext.field;
    })?.max;

    return <String, dynamic>{
      "errorText": errorText,
      "inputFormatters": inputFormatters,
      "maxLength": maxLength,
    };
 }